package com.taihua.faxmail.gol;


import java.io.PrintStream;
import java.sql.*;

public class Database_mysql
{

 private String DBDriver;
 private String ConnStr;
 private String user;
 private String password;
 private Connection conn;
 private Statement stmt;
 private ResultSet rs;
 

 public Database_mysql()
 {
     DBDriver = "org.gjt.mm.mysql.Driver";
    /* ConnStr = "jdbc:microsoft:sqlserver://61.138.179.131:1433;databasename=ymaildb";
     user = "ymaildb";
     password = "ymaildb!@#$%";
     */
     ConnStr = "jdbc:mysql://localhost:3306/mail?useUnicode=true&amp;characterEncoding=GBK";
     user = "root";
     password = "root";
     conn = null;
     stmt = null;
     rs = null;
     try
     {
         Class.forName(DBDriver);
     }
     catch(ClassNotFoundException e)
     {
         System.err.println("database(): " + e.getMessage());
     }
 }

 public ResultSet executeQuery(String sql)
 {
     try
     {
         conn = DriverManager.getConnection(ConnStr, user, password);
         stmt = conn.createStatement();
         rs = stmt.executeQuery(sql);
     }
     catch(SQLException e)
     {
         System.out.println("executeQuery:" + e.getMessage());
     }
     return rs;
 }
/*public String  executeInsert(String sql)
{
    try
    {
        conn = DriverManager.getConnection(ConnStr, user, password);
        stmt = conn.createStatement();
        rs = stmt.e(sql);
    }
    catch(SQLException e)
    {
        System.out.println("executeQuery:" + e.getMessage());
    }
    return "dd";
}*/
 public void executeUpdate(String sql)
 {
     try
     {
         conn = DriverManager.getConnection(ConnStr, user, password);
         conn.setAutoCommit(false);
         stmt = conn.createStatement();
         try
         {
             stmt.executeUpdate(sql);
             conn.commit();
         }
         catch(SQLException e)
         {
             conn.rollback();
             System.out.println("Database Exception:" + e.getMessage());
         }
     }
     catch(SQLException e)
     {
         System.err.println("executeUpdate:" + e.getMessage());
     }
 }

 public void closeStmt()
 {
     try
     {
         stmt.close();
     }
     catch(SQLException e)
     {
         e.printStackTrace();
     }
 }

 public void closeConn()
 {
     try
     {
         conn.close();
     }
     catch(SQLException e)
     {
         e.printStackTrace();
     }
 }
 
 public static void main(String[] args) {	
	
		Database_mysql db2=new Database_mysql();
	    ResultSet rs2=null;

	   String sql="select  username,domainName,maxSize,curSize from users";
	    rs2=db2.executeQuery(sql);
	    try {
			while(rs2.next())
			{	System.out.println("---");
				
			}
			
			
			
		} catch (SQLException e) {
		
		}
	 
 }
}
